import {ChangeDetectorRef, Component, Input, OnInit} from '@angular/core';
import {FileInfo} from "@shared/models/FileInfo";
import {DiskService} from "@core/service/DiskService";

@Component({
  selector: 'app-text-editor',
  templateUrl: './text-editor.component.html',
  styleUrls: ['./text-editor.component.scss']
})
export class TextEditorComponent implements OnInit {
  @Input()
  text=
`ngOnInit(): void {
    const myObserver = new ResizeObserver(entries => {
      entries.forEach(entry => {
        console.log(entry.contentRect.height)
        let cnt = Math.ceil((entry.contentRect.height-2)/22)nt = Math.ceil((entry.contentRect.height-2)/22)nt = Math.ceil((entry.contentRect.height-2)/22)nt = Math.ceil((entry.contentRect.height-2)/22)nt = Math.ceil((entry.contentRect.height-2)/22)nt = Math.ceil((entry.contentRect.height-2)/22)nt = Math.ceil((entry.contentRect.height-2)/22)
        let oldCnt =    this.lines.length
        let change = cnt-oldCnt
        if (change>=0){
          for (let i = 0; i < change; i++) {
            this.lines.push(1+this.lines.length)
          }


        }else {
          change=-change
          for (let i = 0; i < change; i++) {
            this.lines.pop()
          }
        }
        console.log(cnt)
        this.cdr.detectChanges()
      })
    })
    let el = d
`
  lines:string[]=[]
  line_cnt:number[]=[]
  constructor(private cdr:ChangeDetectorRef) {
  }

  ngOnInit(): void {

    let lines=this.text.split("\n");
    let line_cnt=[]
    for (let i = 1; i <= lines.length; i++) {
      line_cnt.push(i)
    }
    this.lines=lines
    this.line_cnt=line_cnt

    // const myObserver = new ResizeObserver(entries => {
    //   entries.forEach(entry => {
    //     console.log(entry.contentRect.height)
    //     let cnt = Math.ceil((entry.contentRect.height-2)/22)
    //     let oldCnt = this.lines.length
    //     let change = cnt-oldCnt
    //     if (change>=0){
    //       for (let i = 0; i < change; i++) {
    //         this.lines.push(1+this.lines.length)
    //       }
    //     }else {
    //       change=-change
    //       for (let i = 0; i < change; i++) {
    //         this.lines.pop()
    //       }
    //     }
    //     console.log(cnt)
    //     this.cdr.detectChanges()
    //   })
    // })
    // let el = document.getElementById("inputEditor")
    // if (el) {
    //   myObserver.observe(el)
    // }
  }
}
